using System.Collections.Generic;

namespace Silvery
{
    
    /// <summary>
    /// 屏，屏是游戏中的平面显示基本，继承自DynamicObject自身拥有一定的循环逻辑
    /// 通常使用作为UI的部分解决
    /// </summary>
    public class NScreen : DynamicObject, IBaseObjCollection
    {
        /// <summary>
        /// 构造
        /// </summary>
        public NScreen()
        {
            Appendage = new List<BaseObject>();
        }
        /// <summary>
        /// 添加基本物体到屏中
        /// </summary>
        /// <param name="obj"></param>
        public virtual void AddBaseObj(BaseObject obj)
        {
            this.Children.Add(obj);
            Appendage.Add(obj);
        }
        /// <summary>
        /// 移除基本物体从屏中
        /// </summary>
        /// <param name="obj"></param>
        public virtual void RemoveBaseObj(BaseObject obj)
        {
            this.Children.Remove(obj);
            Appendage.Remove(obj);
        }
        /// <summary>
        /// 一个简单的统计
        /// </summary>
        public virtual int BaseObjectsCount
        {
            get { return Appendage.Count; }
        }
        /// <summary>
        /// 新增
        /// </summary>
        public List<BaseObject> Appendage { get; private set; }
        /// <summary>
        /// 销毁
        /// </summary>
        public override void Dispose()
        {
            foreach (var item in Appendage)
                this.Children.Remove(item);
            Appendage.Clear(); 
            Appendage = null;
            base.Dispose();
        }

        /// <summary>
        /// 
        /// </summary>
        public System.Windows.Controls.UIElementCollection GameObjects
        {
            get { return Children; }
        }
    }
}
